import java.awt.*;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 徐海涛
 * Date: 2021-11-22
 * Time: 17:29
 */
public class TestDemo {
    public static void main10(String[] args) {//以大化小，找终止条件
        int n = 10;//找个函数值，返回
        int ret = fac(n);
        System.out.println(ret);
    }

    public static int fac(int n) {
        if (n == 1) {
            return 1;
        } else {
            return n * fac(n - 1);
        }
    }

    public static void main9(String[] args) {//递归求 1 + 2 + 3 + ... + 10
        int n = 10;//递归抓住以大化小，要返回return，找个终止条件，找个函数（！！返回那个函数，递下去）
        System.out.println(sumAdd(n));//归回来。
    }

    public static int sumAdd(int n) {
        if (n == 1) {
            return 1;
        } else {
            return n + sumAdd(n - 1);
        }
    }

    public static void main8(String[] args) {
        pirnt1(123);
    }

    public static int pirnt1(int n) {
        if (n < 10) { //个位数除10的余数为1！！！
            System.out.println(n % 10 + " ");
            return n;
        } else {
            pirnt1(n / 10);
            System.out.println(n % 10 + " ");
            return n;
        }
    }

    public static void main7(String[] args) { // 写一个递归方法，输入一个非负整数，返回组成它的数字之和
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ret = add(n);
        System.out.println(ret);
        sc.close();
    }

    public static int add(int n) {
        if (n < 10) {
            return n;
        }
        return n % 10 + add(n / 10);
    }










    public static void main(String[] args) {
        int sum = 0;
        sumPrint(123);
        System.out.println(sumPrint(123));
    }

    public static int sumPrint(int n) {
        if (n < 10) {
            return n;
        } else {
            return n / 10 + sumPrint(n % 10);
        }
    }























    public static void main5(String[] args) { //递归打印每一位数
       int n = 123;
       print(n);
    }
    public static int print(int n) {
        if (n < 10) {
            System.out.println(n%10 + " ");
            return n;
        } else {
            print(n/10);
            System.out.println(n % 10 + " ");
            return n;
        }
    }






















    public static void main4(String[] args) { //递归求斐波那契数列的第 N 项
        int n = 4;
        fib(n);
        System.out.println(fib(n));
    }
    public static int fib(int n) {
        if (n==1 || n==2) {
            return n;
        }else {
            return fib(n-1)+fib(n-2);
        }
    }



























    private static int count = 0;
    private static int count3;
    public static void main2(String[] args) {
       Scanner scanner = new Scanner(System.in);
       int n = scanner.nextInt();
       char x ='x',y='y',z='z';
       hanio(n,x,y,z);
        System.out.println("一共移动了" + count + "次" + " ");
    }
    public static void hanio(int n ,char x ,char y ,char z) {
        count3++;
        if(n==1) {
            move(n,x,z);
        }else {
            hanio(n-1,x,z,y);
            move(n,x,z);
            hanio(n-1,y,x,z);
        }
    }
    public static void move(int n ,char x ,char y) {
        System.out.println("把第" + n + "个盘子" + "从" + x + "移动到" + y);
    }


























    //////////////////////////////////////////////////////////////////青蛙跳台阶问题
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        System.out.println(func(n));
    }
    public static int func(int n) {
        if(n==1 || n == 2) {
            return n;
        }else {
            return fac(n-1)+fac(n-2);
        }
    }
}



